package autoApi;

import org.openqa.selenium.By;
import org.openqa.selenium.edge.EdgeDriver;

import javax.swing.plaf.SpinnerUI;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-04-06
 * Time: 7:29
 */
public class ApiDemo1 {
    // 自动化登陆测试
    public void login () throws InterruptedException {

        // 1. 创建驱动浏览器实例
        EdgeDriver driver = new EdgeDriver();

        Thread.sleep(2000);

        // 2. 打开博客地址
        driver.get("http://124.221.91.27:8080/My_blog_System/login.html");

        Thread.sleep(2000);

        // 3. 获取用户名元素和密码元素输入账号密码
        driver.findElement(By.cssSelector("#username")).sendKeys("1843977391");
        driver.findElement(By.cssSelector("#password")).sendKeys("lyf2021.");

        Thread.sleep(2000);

        // 4. 获取登陆元素并点击登陆
        // 需要注意的是, submit() 方法点击只适合 a 标签
        driver.findElement(By.cssSelector("#submit")).click();

        Thread.sleep(2000);

        // 5. 关闭浏览器资源
        driver.quit();
    }

    public void backspace() throws InterruptedException {
        // 1. 创建驱动浏览器实例
        EdgeDriver driver = new EdgeDriver();
        Thread.sleep(2000);

        // 2. 打开百度地址
        driver.get("https://www.baidu.com");
        Thread.sleep(2000);

        // 3. 获取输入框标签
        driver.findElement(By.cssSelector("#kw")).sendKeys("你号啊!");
        Thread.sleep(2000);

        // 4. 输入错误进行清除
        driver.findElement(By.cssSelector("#kw")).clear();
        // 重新输入内容
        driver.findElement(By.cssSelector("#kw")).sendKeys("你好啊");
        Thread.sleep(2000);

        // 5. 关闭资源
        driver.quit();
    }


}
